package com.shiyingzi.auser.controller;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.shiyingzi.auser.model.AUser;
import com.shiyingzi.auser.service.AUserService;
import com.shiyingzi.common.PageableData;
import com.shiyingzi.common.ResponseData;
import com.shiyingzi.product.model.AppABasicInformation;
import com.shiyingzi.utils.MDFiveUtils;

@RestController
@RequestMapping(value = "auser")
public class AUserController {	
	@Resource(name = AUserService.BEAN_ID)
	private AUserService aUserService;
	
	@RequestMapping(value = "/ainesrt", method = {RequestMethod.GET,RequestMethod.POST })
	public ResponseData inserAUser(AUser auser){
		return aUserService.addAUser(auser);
	}
	
	@RequestMapping(value = "/doALogin", method = {RequestMethod.GET,RequestMethod.POST })
	public ResponseData doALogin(AUser auser){
		return aUserService.doALogin(auser);
	}
	
	@RequestMapping(value = "/query", method = { RequestMethod.GET, RequestMethod.POST })
	public PageableData<AUser> doQuery(int page, int limit, String userName){
		return aUserService.queryAUserList(page, limit, userName);
	}
	
	@RequestMapping(value = "/update", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData update(AUser auser){
		return aUserService.updateAUser(auser);
	}
	
	@RequestMapping(value = "/upPasswordById", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData upPasswordById(AUser auser){
		AUser au=aUserService.getProductById(auser.getId());
		au.setUsPassword(MDFiveUtils.encrypt(auser.getUsPassword()));
		return aUserService.updateAUser(au);
	}
	
	@RequestMapping(value = "/updateStateById", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData updateStateById(AUser auser){
		AUser au=aUserService.getProductById(auser.getId());
		au.setUsState(auser.getUsState());
		return aUserService.updateAUser(au);
	}
}
